using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
using System.IO;

using Jamila2.CoreElements;
using Jamila2.Tools;

public class EmailGenerator : ManagerBase
{
    protected string SourceContent = "";
    private string mail_title = "";

    public string MailTitle
    {
        get
        {
            return this.mail_title;
        }
    }

	public EmailGenerator(string SourceFile, string LanguageID)
	{
        // get the file name
        string FileName = SourceFile + "-" + LanguageID + ".htm";

        // read the file
        using (StreamReader FileReader = new StreamReader(FileName, Encoding.UTF8))
        {
            SourceContent = FileReader.ReadToEnd();
            FileReader.Close();
        }
        
    }

    #region GenerateSubmittedClaimForApprover
    public string GenerateSubmittedClaimForApprover(string EmployeeName, string EmployeeNo, string ADName, string Company, string ReferenceNo, string Purpose, string LocalAmount, string DateSubmitted, string Link)
    {
        StringBuilder EmailBuilder = new StringBuilder(this.SourceContent);

        if (this.SourceContent.Length > 0)
        {
            // replace with data
            EmailBuilder.Replace("#EmployeeName#", EmployeeName);
            EmailBuilder.Replace("#EmployeeNo#", EmployeeNo);
            EmailBuilder.Replace("#ADName#", ADName);
            EmailBuilder.Replace("#Company#", Company);
            EmailBuilder.Replace("#ReferenceNo#", ReferenceNo);
            EmailBuilder.Replace("#Purpose#", Purpose);
            EmailBuilder.Replace("#LocalAmount#", LocalAmount);
            EmailBuilder.Replace("#DateSubmitted#", DateSubmitted);
            EmailBuilder.Replace("#Link#", Link);      
      
            // title
            this.mail_title = this.SourceContent.Substring(
                this.SourceContent.IndexOf("<title>") + "<title>".Length,
                this.SourceContent.IndexOf("</title>") - (this.SourceContent.IndexOf("<title>") + "<title>".Length));
        }
        else
        {
            this.ErrMsg = "[EmailGenerator.GenerateSubmittedClaimForApprover] : No source file";
        }

        return EmailBuilder.ToString();
    }
    #endregion

    #region GenerateApprovedClaimForClaimant
    public string GenerateApprovedClaimForClaimant(string EmployeeName, string EmployeeNo, string ADName, string Company, string ReferenceNo, string Purpose, string LocalAmount, string ApprovedBy, string Link)
    {
        StringBuilder EmailBuilder = new StringBuilder();

        if (this.SourceContent.Length > 0)
        {
            EmailBuilder.Append(this.SourceContent);

            // replace with data
            EmailBuilder.Replace("#EmployeeName#", EmployeeName);
            EmailBuilder.Replace("#EmployeeNo#", EmployeeNo);
            EmailBuilder.Replace("#ADName#", ADName);
            EmailBuilder.Replace("#Company#", Company);
            EmailBuilder.Replace("#ReferenceNo#", ReferenceNo);
            EmailBuilder.Replace("#Purpose#", Purpose);
            EmailBuilder.Replace("#LocalAmount#", LocalAmount);
            EmailBuilder.Replace("#ApprovedBy#", ApprovedBy);
            EmailBuilder.Replace("#Link#", Link);

            // title
            this.mail_title = this.SourceContent.Substring(
                this.SourceContent.IndexOf("<title>") + "<title>".Length,
                this.SourceContent.IndexOf("</title>") - (this.SourceContent.IndexOf("<title>") + "<title>".Length));
        }
        else
        {
            this.ErrMsg = "[EmailGenerator.GenerateApprovedClaimForClaimant] : No source file";
        }

        return EmailBuilder.ToString();
    }
    #endregion

    #region GenerateEscalatedClaimForApprover
    public string GenerateEscalatedClaimForApprover(string EmployeeName, string EmployeeNo, string ADName, string Company, string ReferenceNo, string Purpose, string LocalAmount, string DateSubmitted, string Link)
    {
        StringBuilder EmailBuilder = new StringBuilder();

        if (this.SourceContent.Length > 0)
        {
            EmailBuilder.Append(this.SourceContent);

            // replace with data
            EmailBuilder.Replace("#EmployeeName#", EmployeeName);
            EmailBuilder.Replace("#EmployeeNo#", EmployeeNo);
            EmailBuilder.Replace("#ADName#", ADName);
            EmailBuilder.Replace("#Company#", Company);
            EmailBuilder.Replace("#ReferenceNo#", ReferenceNo);
            EmailBuilder.Replace("#Purpose#", Purpose);
            EmailBuilder.Replace("#LocalAmount#", LocalAmount);
            EmailBuilder.Replace("#DateSubmitted#", DateSubmitted);
            EmailBuilder.Replace("#Link#", Link);

            // title
            this.mail_title = this.SourceContent.Substring(
                this.SourceContent.IndexOf("<title>") + "<title>".Length,
                this.SourceContent.IndexOf("</title>") - (this.SourceContent.IndexOf("<title>") + "<title>".Length));
        }
        else
        {
            this.ErrMsg = "[EmailGenerator.GenerateEscalatedClaimForApprover] : No source file";
        }

        return EmailBuilder.ToString();
    }
    #endregion

    #region GenerateRejectedClaimForClaimant
    public string GenerateRejectedClaimForClaimant(string EmployeeName, string EmployeeNo, string ADName, string Company, string ReferenceNo, string Purpose, string LocalAmount, string Status, string Link)
    {
        StringBuilder EmailBuilder = new StringBuilder();

        if (this.SourceContent.Length > 0)
        {
            EmailBuilder.Append(this.SourceContent);

            // replace with data
            EmailBuilder.Replace("#EmployeeName#", EmployeeName);
            EmailBuilder.Replace("#EmployeeNo#", EmployeeNo);
            EmailBuilder.Replace("#ADName#", ADName);
            EmailBuilder.Replace("#Company#", Company);
            EmailBuilder.Replace("#ReferenceNo#", ReferenceNo);
            EmailBuilder.Replace("#Purpose#", Purpose);
            EmailBuilder.Replace("#LocalAmount#", LocalAmount);
            EmailBuilder.Replace("#Status#", Status);
            EmailBuilder.Replace("#Link#", Link);

            // title
            this.mail_title = this.SourceContent.Substring(
                this.SourceContent.IndexOf("<title>") + "<title>".Length,
                this.SourceContent.IndexOf("</title>") - (this.SourceContent.IndexOf("<title>") + "<title>".Length));
        }
        else
        {
            this.ErrMsg = "[EmailGenerator.GenerateEscalatedClaimForApprover] : No source file";
        }

        return EmailBuilder.ToString();
    }
    #endregion

    #region GenerateRejectedClaimForPreviousApprover
    public string GenerateRejectedClaimForPreviousApprover(string EmployeeName, string EmployeeNo, string ADName, string Company, string ReferenceNo, string Purpose, string LocalAmount, string Status, string Link, string ApprovedDate)
    {
        StringBuilder EmailBuilder = new StringBuilder();

        if (this.SourceContent.Length > 0)
        {
            EmailBuilder.Append(this.SourceContent);

            // replace with data
            EmailBuilder.Replace("#EmployeeName#", EmployeeName);
            EmailBuilder.Replace("#EmployeeNo#", EmployeeNo);
            EmailBuilder.Replace("#ADName#", ADName);
            EmailBuilder.Replace("#Company#", Company);
            EmailBuilder.Replace("#ReferenceNo#", ReferenceNo);
            EmailBuilder.Replace("#Purpose#", Purpose);
            EmailBuilder.Replace("#LocalAmount#", LocalAmount);
            EmailBuilder.Replace("#Status#", Status);
            EmailBuilder.Replace("#Link#", Link);
            EmailBuilder.Replace("#ApprovedDate#", ApprovedDate);

            // title
            this.mail_title = this.SourceContent.Substring(
                this.SourceContent.IndexOf("<title>") + "<title>".Length,
                this.SourceContent.IndexOf("</title>") - (this.SourceContent.IndexOf("<title>") + "<title>".Length));
        }
        else
        {
            this.ErrMsg = "[EmailGenerator.GenerateEscalatedClaimForApprover] : No source file";
        }

        return EmailBuilder.ToString();
    }
    #endregion

    #region GeneratePendingForAuthorizerClaimForAuthorizer
    public string GeneratePendingForAuthorizerClaimForAuthorizer(string EmployeeName, string EmployeeNo, string ADName, string Company, string ReferenceNo, string Purpose, string LocalAmount, string DateSubmitted, string Link)
    {
        StringBuilder EmailBuilder = new StringBuilder();

        if (this.SourceContent.Length > 0)
        {
            EmailBuilder.Append(this.SourceContent);

            // replace with data
            EmailBuilder.Replace("#EmployeeName#", EmployeeName);
            EmailBuilder.Replace("#EmployeeNo#", EmployeeNo);
            EmailBuilder.Replace("#ADName#", ADName);
            EmailBuilder.Replace("#Company#", Company);
            EmailBuilder.Replace("#ReferenceNo#", ReferenceNo);
            EmailBuilder.Replace("#Purpose#", Purpose);
            EmailBuilder.Replace("#LocalAmount#", LocalAmount);
            EmailBuilder.Replace("#DateSubmitted#", DateSubmitted);
            EmailBuilder.Replace("#Link#", Link);

            // title
            this.mail_title = this.SourceContent.Substring(
                this.SourceContent.IndexOf("<title>") + "<title>".Length,
                this.SourceContent.IndexOf("</title>") - (this.SourceContent.IndexOf("<title>") + "<title>".Length));
        }
        else
        {
            this.ErrMsg = "[EmailGenerator.GenerateEscalatedClaimForApprover] : No source file";
        }

        return EmailBuilder.ToString();
    }
    #endregion

    #region GenerateVerifiedClaimForClaimant
    public string GenerateVerifiedClaimForClaimant(string EmployeeName, string EmployeeNo, string ADName, string Company, string ReferenceNo, string Purpose, string LocalAmount, string FinalAmount, string Link)
    {
        StringBuilder EmailBuilder = new StringBuilder();

        if (this.SourceContent.Length > 0)
        {
            EmailBuilder.Append(this.SourceContent);

            // replace with data
            EmailBuilder.Replace("#EmployeeName#", EmployeeName);
            EmailBuilder.Replace("#EmployeeNo#", EmployeeNo);
            EmailBuilder.Replace("#ADName#", ADName);
            EmailBuilder.Replace("#Company#", Company);
            EmailBuilder.Replace("#ReferenceNo#", ReferenceNo);
            EmailBuilder.Replace("#Purpose#", Purpose);
            EmailBuilder.Replace("#LocalAmount#", LocalAmount);
            EmailBuilder.Replace("#FinalAmount#", FinalAmount);
            EmailBuilder.Replace("#Link#", Link);

            // title
            this.mail_title = this.SourceContent.Substring(
                this.SourceContent.IndexOf("<title>") + "<title>".Length,
                this.SourceContent.IndexOf("</title>") - (this.SourceContent.IndexOf("<title>") + "<title>".Length));
        }
        else
        {
            this.ErrMsg = "[EmailGenerator.GenerateEscalatedClaimForApprover] : No source file";
        }

        return EmailBuilder.ToString();
    }
    #endregion
}
